/**
 * class  CheckBoxGroup
 * 多选框组，可获得组的所有Value，和选中Value,也可选中组中所有多选框
 * author haicent
 * email haicent@126.com
 * version 0.01
 */
package as3.component.controls
{
	import as3.component.Component;
	import as3.component.support.BaseCheckBox;
	import as3.component.support.BaseGroup;
	
	public class CheckBoxGroup extends BaseGroup
	{
		public function CheckBoxGroup()
		{
			super();
		}
		
		/**
		 * 添加多选框
		 * @param item 要添加的多选框
		 * 
		 */		
		override public function put(item:Component):void
		{
			if (item is BaseCheckBox)
			{
				if (_list == null) _list = new Array();
				if (_list.indexOf(item) == -1) _list.push(item);
			}
		}
		
		/**
		 * 选择全部 
		 * @param value 是否选中
		 * 
		 */		
		public function selelctAll(value:Boolean):void
		{
			if (_list == null) return;
			var item:BaseCheckBox;
			for (var i:int = 0 ; i < _list.length; i++)
			{
				item = _list[i] as BaseCheckBox;
				item.selected = value;
			}
		}
		
		/**
		 * 获得组的全部Value 
		 * @return Array
		 * 
		 */		
		public function getAllValue():Array
		{			
			if (_list == null) return null;
			
			var return_ary:Array = new Array();
			var item:BaseCheckBox;
			for (var i:int = 0 ; i < _list.length; i++)
			{
				item = _list[i] as BaseCheckBox;
				return_ary.push(item.value);
			}
			return return_ary;
		}
		
		/**
		 * 获得组中 选中(未选中)的value
		 * @param value
		 * @return Array
		 * 
		 */		
		public function getSelectValue(value:Boolean):Array
		{			
			if (_list == null) return null;
			
			var return_ary:Array = new Array();
			var item:BaseCheckBox;
			for (var i:int = 0 ; i < _list.length; i++)
			{
				item = _list[i] as BaseCheckBox;
				if (item.selected) return_ary.push(item.value);
			}
			return return_ary;
		}
	}
}